<template>
	<view>
		<button @click="startScan">开始扫描</button>
		<view v-if="result">
			<!-- <p>扫描结果：</p>
			<p>{{ result }}</p> -->
		</view>
		<u-toast ref="info" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				result: "",
			};
		},
		methods: {
			startScan() {
				uni.scanCode({
					success: (res) => {
						this.result = res.result;
						// console.log(res)
						uni.navigateTo({
							url: `/pages/index/index?title=${this.result}`
						});

					},
					fail: (err) => {
						console.error("扫描失败", err);
						this.$refs.info.show({
							title: '扫描失败' + err,
							type: 'error',
						})
					},
				});
			},
		},
	};
</script>

<style scoped>
	/* 根据实际需要添加样式 */
	button {
		margin: 20px;
		padding: 10px;
		background-color: #007aff;
		color: #fff;
		border: none;
	}
</style>